{include file="common/header"}
<div id="app" v-cloak>
    <div class="el-layout">
        <el-tabs v-model="tab">
    		<el-tab-pane label="基础配置" name="0">
		        <div class="el-pane-warp">
                    <el-form ref="ruleForm" :rules="rules" :model="config" label-width="150px">
                        <el-form-item label="分页数量：" prop="page">
                            <el-input-number v-model="config.page" controls-position="right" :min="1" :max="100"></el-input-number>
                        </el-form-item>
                        <el-form-item label="用户每日发贴限制：" prop="release_limit">
                            <el-input-number v-model="config.release_limit" controls-position="right" :min="1" :max="100"></el-input-number>
                        </el-form-item>
                        <el-form-item label="用户每次发贴审核：" prop="release_review">
                            <el-radio-group v-model="config.release_review">
                                <el-radio :label="0">开启</el-radio>
                                <el-radio :label="1">关闭</el-radio>
                            </el-radio-group>
                        </el-form-item>
                        <el-form-item label="发贴开启验证码：" prop="captcha">
                            <el-radio-group v-model="config.captcha">
                                <el-radio :label="1">开启</el-radio>
                                <el-radio :label="0">关闭</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-form>
                    <div class="el-bottom" style="width: 100%">
                        <el-button 
                            :loading="loading"
                            type="primary" 
                            size="medium" 
                            icon="el-icon-refresh-right"
                            @click="save()">
                            保 存
                        </el-button>
                    </div>
                </div>
    		</el-tab-pane>
    		<el-tab-pane label="自定义字段" name="1">
		        <div class="el-pane-warp">
                    <el-form ref="ruleForm" :rules="rules" :model="config" label-width="0">
                        <el-form-item>
                            <el-field v-model="config.field" label-position="top"></el-field>
                        </el-form-item>
                    </el-form>
                    <div class="el-bottom" style="width: 100%">
                        <el-button 
                            :loading="loading"
                            type="primary" 
                            size="medium" 
                            icon="el-icon-refresh-right"
                            @click="save()">
                            保 存
                        </el-button>
                    </div>
                </div>
    		</el-tab-pane>
        </el-tabs>
	</div>
</div>
<script>
	new Vue({
	    el: '#app',
	    data() {
	        return {
	            tab: '0',
	            config: {:json_encode($config)},
                loading: false,
                updateUrl: "blog/config/index",
                rules: {
                    page: [
                        { required: true, message: '请填写', trigger: 'blur' },
                    ],
                    release_limit: [
                        { required: true, message: '请填写', trigger: 'blur' },
                    ],
                    release_review: [
                        { required: true, message: '请填写', trigger: 'blur' },
                    ],
                    captcha: [
                        { required: true, message: '请填写', trigger: 'blur' },
                    ],
                },
	        }
	    },
	    created() {
	        this.tab = window.location.hash === "" ? '0' : window.location.hash.replace('#', '');
	    },
	    methods: {
	        /**
             * 保存数据
             */
            save() {
                let self = this;
                self.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        self.loading = true;
                        request.post(self.updateUrl, {value: self.config}, function(res){
                            self.loading = false;
                            self.$notify({showClose: true, message: res.message, type: res.status});
                        });
                    } else {
                        return false;
                    }
                });
            },
	    },
	})
</script>
{include file="common/footer"}